<template>
    <div id="authModelEdit">
        <div class="functionalArea">
            <el-form class="formEmbedTable" :model="toDetail">
                <table> 
                    <tr>
                        <td>Transaction Sequence No.</td>
                        <td>{{toDetail.flowNo}}</td>
                                    
                    </tr>
                    <tr>
                        <td>Submit</td>
                        <td>{{toDetail.userAlias}}</td>	
                    </tr>
                </table>
            </el-form>
        </div>
        <div class="functionalArea formEmbedTable">
            
            <el-form class="formEmbedTable" :model="bsnInfo">
                <table> 
                    <tr>
                        <td colspan="2" style="text-align:center;">  {{"Before"}} </td>
                        <td colspan="2" style="text-align:center;"> {{"After"}} </td>		
                    </tr>
                    <tr>
                        <td>Function：</td>
                        <td> {{$tools.dict.imBsnName(oldBsnInfo.bsnCode)}} </td>	
                        <td>Function：</td>
                        <td > {{$tools.dict.imBsnName(bsnInfo.bsnCode)}} </td>	
                    </tr>
                     <tr id="needAuth"> 
                        <td>Function：</td>
                        <td> {{oldBsnInfo.needAuth==0 ? "Immediate Effect":"Mutual authorization"}} </td>	
                        <td>Function：</td>
                        <td > {{bsnInfo.needAuth==0 ? "Immediate Effect":"Mutual authorization"}} </td>	
                    </tr>
                    <tr id="authType"> 
                        <td>Function：</td>
                        <td> {{oldBsnInfo.authType==1 ? "Counter Authorization":oldBsnInfo.authType==2 ? "Audits Authorization":""}} </td>	
                        <td>Function：</td>
                        <td > {{bsnInfo.authType==1 ? "Counter Authorization":this.bsnInfo.authType==2 ? "Audits Authorization":""}} </td>	
                    </tr>
                </table>
                
            </el-form>
            
            <div class="mt20 btnArea tac">
                <el-button type="primary" @click="agree()">Approve</el-button>
                <el-button type="primary" @click="rules()">Reject</el-button>
                <el-button type="primary" @click="backMenu">Back</el-button>
            </div>
        </div>
        <!--拒绝页面弹窗-->
        <el-dialog :visible.sync="dialogTableVisible" :close-on-click-modal="false" :close-on-press-escape="false">
            <el-form ref="rejectForm" :model="rejectForm" class="formEmbedTable">
                <table>
                    <caption>Refusal reason</caption>
                    <tr>
                        <td>Refusal reason</td>
                        <td>
                            <el-form-item prop="rejReason">
                                <el-input placeholder="input Refusal reason" v-model="rejectForm.rejReason"></el-input>
                            </el-form-item>
                        </td>
                    </tr>
                </table>
                <div class="btnArea mt20 tac">
                    <el-button type="primary" @click="dialogTableVisible = false,reject()">Confirm</el-button>
                    <el-button @click="dialogTableVisible=false">Back</el-button>
                </div>
            </el-form>
        </el-dialog>
        <!--拒绝页面弹窗end-->
    </div>
</template>
<script>
    import ghbIcon from '@src/components/icon';
    export default{
        name:'authModelEdit',
        components:{
            ghbIcon
        },
        props:[
            'detailData','toDetail','oldDetailData'
        ],
        mounted(){
            let bsnTemp=this.detailData.bsnImList[0]
            let newBsnTemp={}
            console.log("bsnTemp:"+JSON.stringify(bsnTemp))
            $.each(bsnTemp,function(i,n){
                if(i=="bsnCode"){
                    console.log(i+":"+n.value)
                    newBsnTemp[i]=n.value
                }
                if(i=="needAuth"){
                    newBsnTemp[i]=n.value
                }
                if(i=="authType"){
                    newBsnTemp[i]=n.value
                }
            })
            this.bsnInfo=newBsnTemp;
            
            let bsnOldTemp=this.oldDetailData;
            let oldBsn={};
            this.oldBsnInfo={};
            $.each(bsnOldTemp,function(i,m){
                if(i=="bsnCode" || i=="needAuth" || i=="authType" ||i=="bsnName"){
                    oldBsn[i]=m.value
                }
                
            })
            this.oldBsnInfo=oldBsn;
           this.$tools.utils.compareEdit(this.bsnInfo,this.oldBsnInfo);
        },
        data(){
            return {
                bsnInfo:{bsnCode:'',needAuth:'',authType:''},
                oldBsnInfo:{bsnCode:'',needAuth:'',authType:''},
                rejectForm:{//审核拒绝列表
                    actionFlag:'',bsnAuthList:[],authFlag:'1',rejReason:''
                },
                agreeForm:{
                    actionFlag:'',bsnAuthList:[],authFlag:'0',
                },
                dialogTableVisible:false,
            }
        },
        methods:{
            backMenu(){
                 this.$emit("back")
            },
            rules(){//判断是否选中数据
               this.dialogTableVisible=true;
            },
            agree(){
               //判断是否选中数据
               console.log("toDetail"+JSON.stringify(this.toDetail))
                this.agreeForm.bsnAuthList.push(this.toDetail);
                console.log("agreeForm"+JSON.stringify(this.agreeForm))
                this.$tools.request(this,this.toDetail.bsnCode+"AuthAction.do",this.agreeForm).then(data=>{
                    //console.log("data"+JSON.stringify(data))
                    if(data.body.errorCode==0){
                        this.$message({
                            type:'success',
                            message:'Success',
                            showClose:true,
                        })
                        this.$emit("back")
                    }else{
                        this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                            callback: action => {
                            }
                        })
                    }
                })
            },
            reject(){
                this.rejectForm.bsnAuthList.push(this.toDetail);
                console.log("rejectForm"+JSON.stringify(this.rejectForm))
                this.$tools.request(this,this.toDetail.bsnCode+"AuthAction.do",this.rejectForm).then(data=>{
                    if(data.body.errorCode==0){
                        this.$message({
                            type:'success',
                            message:'Success',
                            showClose:true,
                        })
                        this.$emit("back")
                    }else{
                        this.$alert("System Error Try again", "warning",{
                            confirmButtonText: 'Confirm',
                            callback: action => {
                            }
                        })
                    }
                })
            },
            compareEdit(form1,form2){//比对修改数据返现
                $.each(form1,function(i,n){
                    //console.log("i:"+i+",n:"+n);
                    $.each(form2,function(j,m){
                        if(i==j){
                            if(n.value!=m.value){
                                let id="#"+j;
                                console.log("id:"+id);
                                $(id).children("td:odd").css("color","red");
                            }
                        }
                    })
                    
                })
            },
        },
        
    }

</script>